package com.kabuda.exception;

import com.kabuda.utils.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author kabuda
 * @create 2023-10-17 22:30
 */
//拦截指定controller，返回json
@RestControllerAdvice(annotations = {Controller.class, RestController.class})
public class GlobalExceptionHandler {
    //拦截指定异常
    @ExceptionHandler(LoginException.class)
    public R ServiceExceptionHandler(LoginException e){
        return R.fail(e.getCode(),e.getMsg());
    }
}